<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 5.4.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
  <link rel="mask-icon" href="/images/safari-pinned-tab.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="google-site-verification" content="zhaw_tiwtlyG0csTTPqb0XVHgxiXKYgsLrWbLNrlFSA">
  <meta name="msvalidate.01" content="CF69BFDC6D5AD24F7037CBEF9B558B84">
  <meta name="yandex-verification" content="20d8ac9dbb5dee76">
  <meta name="baidu-site-verification" content="zc2MlowHRQ">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.1/css/all.min.css" integrity="sha256-DfWjNxDkM94fVBWx1H5BMMp0Zq7luBlV8QRcSES7s+0=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pace-js@1.2.4/themes/blue/pace-theme-minimal.css">
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"xlsdg.org","root":"/","images":"/images","scheme":"Pisces","darkmode":true,"version":"8.11.0","exturl":false,"sidebar":{"position":"left","display":"always","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.json","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="Gulp 安装前提条件：电脑已经配置好 Node.js 的环境。 1$ npm install -g gulp-cli">
<meta property="og:type" content="article">
<meta property="og:title" content="Gulp 配置">
<meta property="og:url" content="https://xlsdg.org/p/c6f8aa91.html">
<meta property="og:site_name" content="xLsDg">
<meta property="og:description" content="Gulp 安装前提条件：电脑已经配置好 Node.js 的环境。 1$ npm install -g gulp-cli">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2015-08-13T06:00:00.000Z">
<meta property="article:modified_time" content="2019-05-02T01:44:12.000Z">
<meta property="article:author" content="xLsDg">
<meta property="article:tag" content="Node.js">
<meta property="article:tag" content="Gulp">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://xlsdg.org/p/c6f8aa91.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://xlsdg.org/p/c6f8aa91.html","path":"p/c6f8aa91.html","title":"Gulp 配置"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Gulp 配置 | xLsDg</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-62013560-3"></script>
  <script class="next-config" data-name="google_analytics" type="application/json">{"tracking_id":"UA-62013560-3","only_pageview":false}</script>
  <script src="/js/third-party/analytics/google-analytics.js"></script>

  <script src="/js/third-party/analytics/baidu-analytics.js"></script>
  <script async src="https://hm.baidu.com/hm.js?9a9b63fd96c23bccc070d9afe797bdc5"></script>

  <script async src="//assets.growingio.com/2.1/gio.js"></script>
  <script class="next-config" data-name="growingio_analytics" type="application/json">"93b1fecf6ab1be1a"</script>
  <script src="/js/third-party/analytics/growingio.js"></script>



  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="xLsDg" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">xLsDg</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">Xiao Lu Software Development Group</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">25</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">14</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">41</span></a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li><li class="menu-item menu-item-commonweal"><a href="/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Gulp-%E5%AE%89%E8%A3%85"><span class="nav-number">1.</span> <span class="nav-text">Gulp 安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A8%A1%E6%9D%BF%E6%96%87%E4%BB%B6"><span class="nav-number">2.</span> <span class="nav-text">模板文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E6%A8%A1%E6%9D%BF"><span class="nav-number">3.</span> <span class="nav-text">配置模板</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99"><span class="nav-number">4.</span> <span class="nav-text">参考资料</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="xLsDg"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">xLsDg</p>
  <div class="site-description" itemprop="description">Developer making the web an awesome place.</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">41</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/xlsdg" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;xlsdg" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:xlsdg@qq.com" title="E-Mail → mailto:xlsdg@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/xlsdg" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;xlsdg" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://twitter.com/xlsdg" title="Twitter → https:&#x2F;&#x2F;twitter.com&#x2F;xlsdg" rel="noopener" target="_blank"><i class="fab fa-twitter fa-fw"></i>Twitter</a>
      </span>
  </div>
  <div class="cc-license site-overview-item animated" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="https://cdn.jsdelivr.net/npm/@creativecommons/vocabulary@2020.11.3/assets/license_badges/small/by_nc_nd.svg" alt="Creative Commons"></a>
  </div>


  <div class="links-of-blogroll site-overview-item animated">
    <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://guofh.github.io/" title="https:&#x2F;&#x2F;guofh.github.io&#x2F;" rel="noopener" target="_blank">郭峰浩</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://happyer.github.io/" title="https:&#x2F;&#x2F;happyer.github.io&#x2F;" rel="noopener" target="_blank">成旭</a>
        </li>
    </ul>
  </div>

        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/xlsdg" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://xlsdg.org/p/c6f8aa91.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="xLsDg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="xLsDg">
      <meta itemprop="description" content="Developer making the web an awesome place.">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Gulp 配置 | xLsDg">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Gulp 配置
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2015-08-13 14:00:00" itemprop="dateCreated datePublished" datetime="2015-08-13T14:00:00+08:00">2015-08-13</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2019-05-02 09:44:12" itemprop="dateModified" datetime="2019-05-02T09:44:12+08:00">2019-05-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/01-%E5%B7%A5%E4%BD%9C/" itemprop="url" rel="index"><span itemprop="name">01.工作</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/01-%E5%B7%A5%E4%BD%9C/%E5%89%8D%E7%AB%AF/" itemprop="url" rel="index"><span itemprop="name">前端</span></a>
        </span>
    </span>

  
    <span id="/p/c6f8aa91.html" class="post-meta-item leancloud_visitors" data-flag-title="Gulp 配置" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>11k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>10 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="Gulp-安装"><a href="#Gulp-安装" class="headerlink" title="Gulp 安装"></a>Gulp 安装</h2><p>前提条件：电脑已经配置好 Node.js 的环境。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install -g gulp-cli</span><br></pre></td></tr></table></figure>

<span id="more"></span>

<p>进入工程目录，运行以下命令:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install --save-dev gulp</span><br></pre></td></tr></table></figure>

<p>除了安装 Gulp 以外，不同的项目还需要安装不同的 Gulp 插件模块。常用模块：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">$ npm install --save-dev gulp-load-plugins</span><br><span class="line">$ npm install --save-dev gulp-jshint</span><br><span class="line">$ npm install --save-dev gulp-csslint</span><br><span class="line">$ npm install --save-dev gulp-htmlhint</span><br><span class="line">$ npm install --save-dev gulp-watch</span><br><span class="line">$ npm install --save-dev gulp-shell</span><br><span class="line">$ npm install --save-dev gulp-concat</span><br><span class="line">$ npm install --save-dev gulp-clean</span><br><span class="line">$ npm install --save-dev gulp-less</span><br><span class="line">$ npm install --save-dev gulp-autoprefixer</span><br><span class="line">$ npm install --save-dev gulp-uglify</span><br><span class="line">$ npm install --save-dev gulp-cssmin</span><br><span class="line">$ npm install --save-dev gulp-imagemin</span><br><span class="line">$ npm install --save-dev gulp-htmlmin</span><br></pre></td></tr></table></figure>

<p>或一行命令解决：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install --save-dev gulp-load-plugins gulp-jshint gulp-csslint gulp-htmlhint gulp-watch gulp-shell gulp-concat gulp-clean gulp-less gulp-autoprefixer gulp-uglify gulp-cssmin gulp-imagemin gulp-htmlmin</span><br></pre></td></tr></table></figure>

<h2 id="模板文件"><a href="#模板文件" class="headerlink" title="模板文件"></a>模板文件</h2><p>每次都要输入这么多命令，有时候会记不住。其实我们只需要一个 <code>package.json</code> 文件就可以搞定：</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="attr">&quot;name&quot;</span>: <span class="string">&quot;gulp-demo&quot;</span>,</span><br><span class="line">    <span class="attr">&quot;version&quot;</span>: <span class="string">&quot;1.0.0&quot;</span>,</span><br><span class="line">    <span class="attr">&quot;description&quot;</span>: <span class="string">&quot;just for learn gulp.&quot;</span>,</span><br><span class="line">    <span class="attr">&quot;devDependencies&quot;</span>: &#123;</span><br><span class="line">        <span class="attr">&quot;gulp&quot;</span>: <span class="string">&quot;^3.9.0&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-autoprefixer&quot;</span>: <span class="string">&quot;^2.3.1&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-clean&quot;</span>: <span class="string">&quot;^0.3.1&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-concat&quot;</span>: <span class="string">&quot;^2.6.0&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-csslint&quot;</span>: <span class="string">&quot;^0.1.5&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-cssmin&quot;</span>: <span class="string">&quot;^0.1.7&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-htmlhint&quot;</span>: <span class="string">&quot;^0.3.0&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-htmlmin&quot;</span>: <span class="string">&quot;^1.1.3&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-jshint&quot;</span>: <span class="string">&quot;^1.11.2&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-less&quot;</span>: <span class="string">&quot;^3.0.3&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-load-plugins&quot;</span>: <span class="string">&quot;^0.10.0&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-shell&quot;</span>: <span class="string">&quot;^0.4.2&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-uglify&quot;</span>: <span class="string">&quot;^1.2.0&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;gulp-watch&quot;</span>: <span class="string">&quot;^4.3.4&quot;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">&quot;scripts&quot;</span>: &#123;</span><br><span class="line">        <span class="attr">&quot;test&quot;</span>: <span class="string">&quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">&quot;keywords&quot;</span>: [</span><br><span class="line">      <span class="string">&quot;gulp&quot;</span></span><br><span class="line">    ],</span><br><span class="line">    <span class="attr">&quot;author&quot;</span>: <span class="string">&quot;xLsDg&quot;</span>,</span><br><span class="line">    <span class="attr">&quot;license&quot;</span>: <span class="string">&quot;MIT&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>每次需要使用的时候，将该文件放到项目文件夹下，在终端中输入 <code>npm install</code> 即可自动安装相应的模块。</p>
<h2 id="配置模板"><a href="#配置模板" class="headerlink" title="配置模板"></a>配置模板</h2><p>安装完模块之后，还需要配置一下对应的工作参数。新建 <code>gulpfile.js</code> 文件与 <code>package.json</code> 文件同一个目录下，内容为：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> cssSrc = <span class="string">&#x27;./less&#x27;</span>;</span><br><span class="line"><span class="keyword">var</span> cssDst = <span class="string">&#x27;./css&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> jsSrc = <span class="string">&#x27;./js/page&#x27;</span>;</span><br><span class="line"><span class="keyword">var</span> jsDst = <span class="string">&#x27;./js/dist&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> htmlSrc = <span class="string">&#x27;./views/**&#x27;</span>;</span><br><span class="line"><span class="keyword">var</span> htmlDst = <span class="string">&#x27;./html&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> gulp = <span class="built_in">require</span>(<span class="string">&#x27;gulp&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> plugins = <span class="built_in">require</span>(<span class="string">&#x27;gulp-load-plugins&#x27;</span>)(&#123;</span><br><span class="line">        <span class="attr">pattern</span>: [<span class="string">&#x27;gulp-*&#x27;</span>, <span class="string">&#x27;gulp.*&#x27;</span>],</span><br><span class="line">        <span class="attr">config</span>: __dirname + <span class="string">&#x27;/package.json&#x27;</span>,</span><br><span class="line">        <span class="attr">scope</span>: [<span class="string">&#x27;devDependencies&#x27;</span>],</span><br><span class="line">        <span class="attr">replaceString</span>: <span class="regexp">/^gulp(-|\.)/</span>, <span class="comment">// what to remove from the name of the module when adding it to the context</span></span><br><span class="line">        camelize: <span class="literal">true</span>, <span class="comment">// if true, transforms hyphenated plugins names to camel case</span></span><br><span class="line">        <span class="attr">lazy</span>: <span class="literal">true</span>, <span class="comment">// whether the plugins should be lazy loaded on demand</span></span><br><span class="line">        <span class="attr">rename</span>: &#123;&#125; <span class="comment">// a mapping of plugins to rename</span></span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;concat-css&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src([cssDst + <span class="string">&#x27;/*.css&#x27;</span>, <span class="string">&#x27;!&#x27;</span> + cssDst + <span class="string">&#x27;/all.css&#x27;</span>])</span><br><span class="line">        .pipe(plugins.concat(<span class="string">&#x27;all.css&#x27;</span>))</span><br><span class="line">        .pipe(gulp.dest(cssDst));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;clean-css&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src([cssDst + <span class="string">&#x27;/*.css&#x27;</span>], &#123;</span><br><span class="line">            <span class="string">&#x27;read&#x27;</span>: <span class="literal">false</span></span><br><span class="line">        &#125;)</span><br><span class="line">        .pipe(plugins.clean(&#123;</span><br><span class="line">            <span class="string">&#x27;force&#x27;</span>: <span class="literal">false</span></span><br><span class="line">        &#125;));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;build-css&#x27;</span>, [<span class="string">&#x27;clean-css&#x27;</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src([cssSrc + <span class="string">&#x27;/*.less&#x27;</span>, <span class="string">&#x27;!&#x27;</span> + cssSrc + <span class="string">&#x27;/variable.less&#x27;</span>])</span><br><span class="line">        .pipe(plugins.less())</span><br><span class="line">        .pipe(plugins.csslint(&#123;</span><br><span class="line">            <span class="string">&#x27;important&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;adjoining-classes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;known-properties&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;box-sizing&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;box-model&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;overqualified-elements&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;display-property-grouping&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;bulletproof-font-face&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;compatible-vendor-prefixes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;regex-selectors&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;errors&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;duplicate-background-images&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;duplicate-properties&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;empty-rules&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;selector-max-approaching&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;gradients&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;fallback-colors&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;font-sizes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;font-faces&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;floats&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;star-property-hack&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;outline-none&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;import&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;ids&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;underscore-property-hack&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;rules-count&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;qualified-headings&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;selector-max&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;shorthand&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;text-indent&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;unique-headings&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;universal-selector&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;unqualified-attributes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;vendor-prefix&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;zero-units&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;force&#x27;</span>: <span class="literal">true</span></span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(plugins.csslint.reporter())</span><br><span class="line">        .pipe(plugins.autoprefixer(&#123;</span><br><span class="line">            <span class="attr">browsers</span>: [</span><br><span class="line">                <span class="string">&#x27;ie &gt;= 8&#x27;</span>,</span><br><span class="line">                <span class="string">&#x27;ff &gt;= 10&#x27;</span>,</span><br><span class="line">                <span class="string">&#x27;chrome &gt;= 20&#x27;</span>,</span><br><span class="line">                <span class="string">&#x27;safari &gt;= 7&#x27;</span>,</span><br><span class="line">                <span class="string">&#x27;opera &gt;= 10&#x27;</span>,</span><br><span class="line">                <span class="string">&#x27;ios &gt;= 7&#x27;</span>,</span><br><span class="line">                <span class="string">&#x27;android &gt;= 2.3&#x27;</span></span><br><span class="line">            ]</span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(plugins.cssmin(&#123;</span><br><span class="line">            <span class="string">&#x27;compatibility&#x27;</span>: <span class="string">&#x27;ie8&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;noAdvanced&#x27;</span>: <span class="literal">true</span></span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(gulp.dest(cssDst));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;concat-js&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src([jsDst + <span class="string">&#x27;/*.js&#x27;</span>, <span class="string">&#x27;!&#x27;</span> + jsDst + <span class="string">&#x27;/all.js&#x27;</span>])</span><br><span class="line">        .pipe(plugins.concat(<span class="string">&#x27;all.js&#x27;</span>))</span><br><span class="line">        .pipe(gulp.dest(jsDst));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;clean-js&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src([jsDst + <span class="string">&#x27;/*.js&#x27;</span>], &#123;</span><br><span class="line">            <span class="string">&#x27;read&#x27;</span>: <span class="literal">false</span></span><br><span class="line">        &#125;)</span><br><span class="line">        .pipe(plugins.clean(&#123;</span><br><span class="line">            <span class="string">&#x27;force&#x27;</span>: <span class="literal">false</span></span><br><span class="line">        &#125;));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;build-js&#x27;</span>, [<span class="string">&#x27;clean-js&#x27;</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src([jsSrc + <span class="string">&#x27;/*.js&#x27;</span>])</span><br><span class="line">        .pipe(plugins.jshint(&#123;</span><br><span class="line">            <span class="string">&#x27;jquery&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 检查预定义的全局变量，防止出现$未定义，该项根据实际代码修改</span></span><br><span class="line">            <span class="string">&#x27;bitwise&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不检查位运算</span></span><br><span class="line">            <span class="string">&#x27;browser&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 通过浏览器内置的全局变量检测</span></span><br><span class="line">            <span class="string">&#x27;devel&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 允许对调试用的alert和console.log的调用</span></span><br><span class="line">            <span class="string">&#x27;camelcase&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 强制验证驼峰式命名</span></span><br><span class="line">            <span class="string">&#x27;curly&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 强制使用花括号</span></span><br><span class="line">            <span class="string">&#x27;eqeqeq&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不强制使用===比较运算符</span></span><br><span class="line">            <span class="string">&#x27;es3&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 兼容es3规范，针对旧版浏览器编写的代码</span></span><br><span class="line">            <span class="string">&#x27;esnext&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不使用最新的es6规范</span></span><br><span class="line">            <span class="string">&#x27;expr&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 允许未赋值的函数名表达式，例如console &amp;&amp; console.log(1)</span></span><br><span class="line">            <span class="string">&#x27;forin&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不强制过滤遍历对象继承的属性</span></span><br><span class="line">            <span class="string">&#x27;freeze&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不限制对内置对象的扩展</span></span><br><span class="line">            <span class="string">&#x27;immed&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 禁止未用括号包含立即执行函数</span></span><br><span class="line">            <span class="string">&#x27;indent&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不强制缩进</span></span><br><span class="line">            <span class="string">&#x27;latedef&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 禁止先调用后定义</span></span><br><span class="line">            <span class="string">&#x27;maxdepth&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不限制代码块嵌套层数</span></span><br><span class="line">            <span class="string">&#x27;maxparams&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不限制函数参数个数</span></span><br><span class="line">            <span class="string">&#x27;newcap&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不对首字母大写的函数强制使用new</span></span><br><span class="line">            <span class="string">&#x27;noarg&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不禁止对arguments.caller和arguments.callee的调用</span></span><br><span class="line">            <span class="string">&#x27;noempty&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不禁止空代码块</span></span><br><span class="line">            <span class="string">&#x27;nonew&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 允许直接new实例化而不赋值给变量</span></span><br><span class="line">            <span class="string">&#x27;plusplus&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 允许++和--运算符使用</span></span><br><span class="line">            <span class="string">&#x27;quotmark&#x27;</span>: <span class="string">&#x27;single&#x27;</span>, <span class="comment">// 字符串使用单引号</span></span><br><span class="line">            <span class="string">&#x27;scripturl&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 允许javascript伪协议的url</span></span><br><span class="line">            <span class="string">&#x27;smarttabs&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 允许混合tab和空格缩进</span></span><br><span class="line">            <span class="string">&#x27;strict&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 不强制使用es5严格模式</span></span><br><span class="line">            <span class="string">&#x27;sub&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 允许用[]形式访问对象属性</span></span><br><span class="line">            <span class="string">&#x27;undef&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 禁止明确未定义的变量调用，如果你的变量（myvar）是在其他文件中定义的，可以使用/*global myvar */绕过检测</span></span><br><span class="line">            <span class="string">&#x27;unused&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 允许定义没用的变量，在某些函数回调中，经常出现多个参数，但不一定会用</span></span><br><span class="line">            <span class="string">&#x27;multistr&#x27;</span>: <span class="literal">false</span>, <span class="comment">// 禁止多行字符串，改用加号连接</span></span><br><span class="line">            <span class="string">&#x27;globals&#x27;</span>: &#123;</span><br><span class="line">                <span class="string">&#x27;jQuery&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">                <span class="string">&#x27;FastClick&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">                <span class="string">&#x27;define&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">                <span class="string">&#x27;unescape&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">                <span class="string">&#x27;require&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">                <span class="string">&#x27;iScroll&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">                <span class="string">&#x27;host&#x27;</span>: <span class="literal">true</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(plugins.jshint.reporter(<span class="string">&#x27;default&#x27;</span>))</span><br><span class="line">        .pipe(plugins.uglify())</span><br><span class="line">        .pipe(gulp.dest(jsDst));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;clean-html&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src([htmlDst + <span class="string">&#x27;/*.html&#x27;</span>], &#123;</span><br><span class="line">            <span class="string">&#x27;read&#x27;</span>: <span class="literal">false</span></span><br><span class="line">        &#125;)</span><br><span class="line">        .pipe(plugins.clean(&#123;</span><br><span class="line">            <span class="string">&#x27;force&#x27;</span>: <span class="literal">false</span></span><br><span class="line">        &#125;));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;build-html&#x27;</span>, [<span class="string">&#x27;clean-html&#x27;</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src([htmlSrc + <span class="string">&#x27;/*.html&#x27;</span>])</span><br><span class="line">        .pipe(plugins.htmlhint(&#123;</span><br><span class="line">            <span class="string">&#x27;tagname-lowercase&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;attr-lowercase&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;attr-value-double-quotes&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;attr-value-not-empty&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;attr-no-duplication&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;doctype-first&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;tag-pair&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;tag-self-close&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;spec-char-escape&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;id-unique&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;src-not-empty&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;head-script-disabled&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;img-alt-require&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;doctype-html5&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;id-class-value&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;style-disabled&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;space-tab-mixed-disabled&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;id-class-ad-disabled&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;href-abs-or-rel&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;attr-unsafe-chars&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;force&#x27;</span>: <span class="literal">true</span></span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(plugins.htmlhint.reporter())</span><br><span class="line">        .pipe(plugins.htmlmin(&#123;</span><br><span class="line">            <span class="string">&#x27;removeComments&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeCommentsFromCDATA&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeCDATASectionsFromCDATA&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;collapseWhitespace&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&#x27;conservativeCollapse&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;preserveLineBreaks&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;collapseBooleanAttributes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeAttributeQuotes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeRedundantAttributes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;preventAttributesEscaping&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;useShortDoctype&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeEmptyAttributes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeScriptTypeAttributes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeStyleLinkTypeAttributes&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeOptionalTags&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeIgnored&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;removeEmptyElements&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;lint&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;keepClosingSlash&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;caseSensitive&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;minifyJS&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;minifyCSS&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;minifyURLs&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">            <span class="string">&#x27;ignoreCustomComments&#x27;</span>: [],</span><br><span class="line">            <span class="string">&#x27;processScripts&#x27;</span>: [],</span><br><span class="line">            <span class="string">&#x27;maxLineLength&#x27;</span>: [],</span><br><span class="line">            <span class="string">&#x27;customAttrAssign&#x27;</span>: [],</span><br><span class="line">            <span class="string">&#x27;customAttrSurround&#x27;</span>: [],</span><br><span class="line">            <span class="string">&#x27;customAttrCollapse&#x27;</span>: []</span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(gulp.dest(htmlDst));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;clean-all&#x27;</span>, [<span class="string">&#x27;clean-css&#x27;</span>, <span class="string">&#x27;clean-js&#x27;</span>, <span class="string">&#x27;clean-html&#x27;</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;Clean all files finish.&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;build-all&#x27;</span>, [<span class="string">&#x27;build-css&#x27;</span>, <span class="string">&#x27;build-js&#x27;</span>, <span class="string">&#x27;build-html&#x27;</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;Build all files finish.&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;no-html&#x27;</span>, [<span class="string">&#x27;build-css&#x27;</span>, <span class="string">&#x27;build-js&#x27;</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;Build all files finish.&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line">gulp.task(<span class="string">&#x27;no-js&#x27;</span>, [<span class="string">&#x27;build-css&#x27;</span>, <span class="string">&#x27;build-html&#x27;</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;Build all files finish.&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line">gulp.task(<span class="string">&#x27;no-css&#x27;</span>, [<span class="string">&#x27;build-js&#x27;</span>, <span class="string">&#x27;build-html&#x27;</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;Build all files finish.&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;watch&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    gulp.watch([cssSrc + <span class="string">&#x27;/*.less&#x27;</span>, jsSrc + <span class="string">&#x27;/*.js&#x27;</span>, htmlSrc + <span class="string">&#x27;/*.html&#x27;</span>], [<span class="string">&#x27;build-all&#x27;</span>]).on(<span class="string">&#x27;change&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&#x27;Event type: &#x27;</span> + event.type);</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&#x27;Event path: &#x27;</span> + event.path);</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">&#x27;default&#x27;</span>, [<span class="string">&#x27;build-all&#x27;</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;Build all files finish.&#x27;</span>);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>以上内容需根据实际项目情况小做修改即可。</p>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><p>1.<a target="_blank" rel="noopener" href="http://javascript.ruanyifeng.com/tool/gulp.html">Gulp：任务自动管理工具</a></p>

    </div>

    
    
    
      


    <footer class="post-footer">
          <div class="reward-container">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechatpay.png" alt="xLsDg 微信">
        <span>微信</span>
      </div>
      <div>
        <img src="/images/alipay.png" alt="xLsDg 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>xLsDg
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://xlsdg.org/p/c6f8aa91.html" title="Gulp 配置">https://xlsdg.org/p/c6f8aa91.html</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-ND</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="followme">
  <span>欢迎关注我的其它发布渠道</span>

  <div class="social-list">

      <div class="social-item">
        <a target="_blank" class="social-link" href="https://twitter.com/xlsdg">
          <span class="icon">
            <i class="fab fa-twitter"></i>
          </span>

          <span class="label">Twitter</span>
        </a>
      </div>

      <div class="social-item">
        <a target="_blank" class="social-link" href="/atom.xml">
          <span class="icon">
            <i class="fa fa-rss"></i>
          </span>

          <span class="label">RSS</span>
        </a>
      </div>
  </div>
</div>

          <div class="post-tags">
              <a href="/tags/Node-js/" rel="tag"># Node.js</a>
              <a href="/tags/Gulp/" rel="tag"># Gulp</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/p/54a1cf5b.html" rel="prev" title="花密 PHP 核心代码">
                  <i class="fa fa-chevron-left"></i> 花密 PHP 核心代码
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/p/61d0424f.html" rel="next" title="Grunt 配置">
                  Grunt 配置 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments utterances-container"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2015 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xLsDg</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">139k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:07</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  
<script src="https://cdn.jsdelivr.net/npm/hexo-generator-searchdb@1.4.0/dist/search.js" integrity="sha256-vXZMYLEqsROAXkEw93GGIvaB2ab+QW6w3+1ahD9nXXA=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/pace.js"></script>

  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>


  <script class="next-config" data-name="leancloud_visitors" type="application/json">{"enable":true,"app_id":"kS9fC0iDa3h8EEFlbK5BHKxY-MdYXbMMI","app_key":"uqTkCbm6jRHkwFOiIDe2qb3i","server_url":null,"security":true}</script>
  <script src="/js/third-party/statistics/lean-analytics.js"></script>


<script class="next-config" data-name="utterances" type="application/json">{"enable":true,"repo":"xlsdg/blog-comments","issue_term":"pathname","theme":"github-light"}</script>
<script src="/js/third-party/comments/utterances.js"></script>

</body>
</html>
